/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       artifact_keyword.cpp

	$Header: /game/artifact_keyword.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "artifact_keyword.h"

#include <assert.h>
#include <memory.h>
#include "artifact_slot.h"
#include "artifact_type.h"
#include "elements_of.h"
#include "enum_map.h"

namespace
{
	t_char_ptr_pair const k_artifact_keywords[] =
	{
		{ k_artifact_adamantine_armor,				"adamantine_armor"},
		{ k_artifact_adamantine_shield,				"adamantine_shield"},
		{ k_artifact_amulet_of_fear,				"amulet_of_fear"},
		{ k_artifact_amulet_of_the_undertaker,		"amulet_of_the_undertaker"},
		{ k_artifact_ankh_of_life,					"ankh_of_life"},
		{ k_artifact_apprentices_handbook,			"apprentices_handbook"},
		{ k_artifact_archmages_spellbook,			"archmages_spellbook"},
		{ k_artifact_armor_of_chaos,				"armor_of_chaos"},
		{ k_artifact_armor_of_darkness,				"armor_of_darkness"},
		{ k_artifact_armor_of_light,				"armor_of_light"},
		{ k_artifact_armor_of_order,				"armor_of_order"},
		{ k_artifact_arms_of_legion,				"arms_of_legion"},
		{ k_artifact_arrow_of_slaying,				"arrow_of_slaying"},
		{ k_artifact_arrow_of_stunning,				"arrow_of_stunning"},
		{ k_artifact_axe,							"axe"},
		{ k_artifact_axe_of_legends,				"axe_of_legends"},
		{ k_artifact_badge_of_courage,				"badge_of_courage"},
		{ k_artifact_bag_of_gold,					"bag_of_gold"},
		{ k_artifact_binding,						"binding"},
		{ k_artifact_binding_liquid,				"binding_liquid"},
		{ k_artifact_blank_shield,					"blank_shield"},
		{ k_artifact_barbarian_throwing_club,		"barbarian_throwing_club"},
		{ k_artifact_book_of_enchantment,			"book_of_enchantment"},
		{ k_artifact_boots_of_levitation,			"boots_of_levitation"},
		{ k_artifact_boots_of_speed,				"boots_of_speed"},
		{ k_artifact_bow_of_the_white_stag,			"bow_of_the_white_stag"},
		{ k_artifact_brazier_of_sulfur,				"brazier_of_sulfur"},
		{ k_artifact_breastplate_of_regeneration,	"breastplate_of_regeneration"},
		{ k_artifact_brimstone_breastplate,			"brimstone_breastplate"},
		{ k_artifact_caduceus,						"caduceus"},
		{ k_artifact_cap_of_knowledge,				"cap_of_knowledge"},
		{ k_artifact_cape_of_protection,			"cape_of_protection"},
		{ k_artifact_cart_of_lumber,				"cart_of_lumber"},
		{ k_artifact_cart_of_ore,					"cart_of_ore"},
		{ k_artifact_centaurs_spear,				"centaurs_spear"},
		{ k_artifact_chain,							"chain"},
		{ k_artifact_chainmail,						"chainmail"},
		{ k_artifact_chapter_four,					"chapter_four"},
		{ k_artifact_chapter_one,					"chapter_one"},
		{ k_artifact_chapter_three,					"chapter_three"},
		{ k_artifact_chapter_two,					"chapter_two"},
		{ k_artifact_circlet_of_wisdom,				"circlet_of_wisdom"},
		{ k_artifact_cloak_of_confusion,			"cloak_of_confusion"},
		{ k_artifact_cloud_of_despair,				"cloud_of_despair"},
		{ k_artifact_compass,						"compass"},
		{ k_artifact_cowl_of_resistance,			"cowl_of_resistance"},
		{ k_artifact_crest_of_valor,				"crest_of_valor"},
		{ k_artifact_crossbow,						"crossbow"},
		{ k_artifact_crown,							"crown"},
		{ k_artifact_crown_of_dragon_teeth,			"crown_of_dragon_teeth"},
		{ k_artifact_crown_of_the_mind,				"crown_of_the_mind"},
		{ k_artifact_crystal_of_light,				"crystal_of_light"},
		{ k_artifact_crystal_of_memory,				"crystal_of_memory"},
		{ k_artifact_cube_of_crystals,				"cube_of_crystals"},
		{ k_artifact_dark_ruby,						"dark_ruby"},
		{ k_artifact_davids_sling,					"davids_sling"},
		{ k_artifact_demon_slayer,					"demon_slayer"},
		{ k_artifact_demonary,						"demonary"},
		{ k_artifact_dragon_scale_armor,			"dragon_scale_armor"},
		{ k_artifact_dragon_scale_shield,			"dragon_scale_shield"},
		{ k_artifact_druids_chain,					"druids_chain"},
		{ k_artifact_dwarven_hammer,				"dwarven_hammer"},
		{ k_artifact_dwarven_shield,				"dwarven_shield"},
		{ k_artifact_ebony_key,						"ebony_key"},
		{ k_artifact_elven_chainmail,				"elven_chainmail"},
		{ k_artifact_emerald_longbow,				"emerald_longbow"},
		{ k_artifact_equestrians_gloves,			"equestrians_gloves"},
		{ k_artifact_fire_snake,					"fire_snake"},
		{ k_artifact_fireproof_boots,				"fireproof_boots"},
		{ k_artifact_fizbin_of_misfortune,			"fizbin_of_misfortune"},
		{ k_artifact_flaming_arrow,					"flaming_arrow"},
		{ k_artifact_flaming_sword,					"flaming_sword"},
		{ k_artifact_flask_of_mercury,				"flask_of_mercury"},
		{ k_artifact_four_leaf_clover,				"four_leaf_clover"},
		{ k_artifact_gamblers_deck,					"gamblers_deck"},
		{ k_artifact_giant_slayer,					"giant_slayer"},
		{ k_artifact_gias_gems,						"gias_gems"},
		{ k_artifact_golden_plate_mail,				"golden_plate_mail"},
		{ k_artifact_greater_ring_of_vulnerability,	"greater_ring_of_vulnerability"},
		{ k_artifact_greatsword,					"greatsword"},
		{ k_artifact_gryphonhearts_plate_mail,		"gryphonhearts_plate_mail"},
		{ k_artifact_guildmasters_compendium,		"guildmasters_compendium"},
		{ k_artifact_halberd_of_speed,				"halberd_of_speed"},
		{ k_artifact_hawkins_bow_of_speed,			"hawkins_bow_of_speed"},
		{ k_artifact_head_of_legion,				"head_of_legion"},
		{ k_artifact_helm_of_command,				"helm_of_command"},
		{ k_artifact_helm_of_power,					"helm_of_power"},
		{ k_artifact_helm_of_vision,				"helm_of_vision"},
		{ k_artifact_hideous_mask,					"hideous_mask"},
		{ k_artifact_holy_crown,					"holy_crown"},
		{ k_artifact_holy_water,					"holy_water"},
		{ k_artifact_horseshoe,						"horseshoe"},
		{ k_artifact_infant_dragon_wings,			"infant_dragon_wings"},
		{ k_artifact_ivory_key,						"ivory_key"},
		{ k_artifact_journeymans_notebook,			"journeymans_notebook"},
		{ k_artifact_kreegan_fire,					"kreegan_fire"},
		{ k_artifact_leather_armor,					"leather_armor"},
		{ k_artifact_left_elephant_tusk,			"left_elephant_tusk"},
		{ k_artifact_left_onyx,						"left_onyx"},
		{ k_artifact_legs_of_legion,				"legs_of_legion"},
		{ k_artifact_leprechauns_ring,				"leprechauns_ring"},
		{ k_artifact_lesser_ring_of_vulnerability,	"lesser_ring_of_vulnerability"},
		{ k_artifact_lions_shield_of_courage,		"lions_shield_of_courage"},
		{ k_artifact_logbook_of_the_master_sailor,	"logbook_of_the_master_sailor"},
		{ k_artifact_longbow,						"longbow"},
		{ k_artifact_longsword,						"longsword"},
		{ k_artifact_mages_robe,					"mages_robe"},
		{ k_artifact_mages_staff,					"mages_staff"},
		{ k_artifact_magic_amplifier,				"magic_amplifier"},
		{ k_artifact_mahogany_key,					"mahogany_key"},
		{ k_artifact_mantle_of_spell_turning,		"mantle_of_spell_turning"},
		{ k_artifact_marantheas_mug,				"marantheas_mug"},
		{ k_artifact_masters_journal,				"masters_journal"},
		{ k_artifact_medal_of_honor,				"medal_of_honor"},
		{ k_artifact_mind_shield,					"mind_shield"},
		{ k_artifact_minotaurs_battleax,			"minotaurs_battleax"},
		{ k_artifact_mirror_of_spell_turning,		"mirror_of_spell_turning"},
		{ k_artifact_monks_mace,					"monks_mace"},
		{ k_artifact_mullichs_helm_of_leadership,	"mullichs_helm_of_leadership"},
		{ k_artifact_necklace_of_charm,				"necklace_of_charm"},
		{ k_artifact_neeners_invulnerable_cloak,	"neeners_invulnerable_cloak"},
		{ k_artifact_nomad_blackbow,				"nomad_blackbow"},
		{ k_artifact_ogs_sandals,					"ogs_sandals"},
		{ k_artifact_orb_of_summoning,				"orb_of_summoning"},
		{ k_artifact_parchment,						"parchment"},
		{ k_artifact_plate_mail,					"plate_mail"},
		{ k_artifact_poison_arrow,					"poison_arrow"},
		{ k_artifact_poison_ring,					"poison_ring"},
		{ k_artifact_potion_of_cold,				"potion_of_cold"},
		{ k_artifact_potion_of_endurance,			"potion_of_endurance"},
		{ k_artifact_potion_of_fire_resistance,		"potion_of_fire_resistance"},
		{ k_artifact_potion_of_healing,				"potion_of_healing"},
		{ k_artifact_potion_of_health,				"potion_of_health"},
		{ k_artifact_potion_of_luck,				"potion_of_luck"},
		{ k_artifact_potion_of_mana,				"potion_of_mana"},
		{ k_artifact_potion_of_mirth,				"potion_of_mirth"},
		{ k_artifact_potion_of_immortality,			"potion_of_precognition"},
		{ k_artifact_potion_of_quickness,			"potion_of_quickness"},
		{ k_artifact_potion_of_resistance,			"potion_of_resistance"},
		{ k_artifact_potion_of_restoration,			"potion_of_restoration"},
		{ k_artifact_potion_of_speed,				"potion_of_speed"},
		{ k_artifact_potion_of_strength,			"potion_of_strength"},
		{ k_artifact_purse_of_gold,					"purse_of_gold"},
		{ k_artifact_purse_of_pennypinching,		"purse_of_pennypinching"},
		{ k_artifact_rams_horn,						"rams_horn"},
		{ k_artifact_rhino_horn,					"rhino_horn"},
		{ k_artifact_right_elephant_tusk,			"right_elephant_tusk"},
		{ k_artifact_right_onyx,					"right_onyx"},
		{ k_artifact_ring_of_elementals,			"ring_of_elementals"},
		{ k_artifact_ring_of_health,				"ring_of_health"},
		{ k_artifact_ring_of_permanency,			"ring_of_permanency"},
		{ k_artifact_ring_of_protection,			"ring_of_protection"},
		{ k_artifact_ring_of_regeneration,			"ring_of_regeneration"},
		{ k_artifact_ring_of_speed,					"ring_of_speed"},
		{ k_artifact_ring_of_strength,				"ring_of_strength"},
		{ k_artifact_rising_sun,					"rising_sun"},
		{ k_artifact_robe_of_the_guardian,			"robe_of_the_guardian"},
		{ k_artifact_rod_of_chaos,					"rod_of_chaos"},
		{ k_artifact_ruby,							"ruby"},
		{ k_artifact_sack_of_gold,					"sack_of_gold"},
		{ k_artifact_sandalwood_key,				"sandalwood_key"},
		{ k_artifact_sandwalker_sandals,			"sandwalker_sandals"},
		{ k_artifact_sapphire,						"sapphire"},
		{ k_artifact_scale_mail_of_strength,		"scale_mail_of_strength"},
		{ k_artifact_scroll,						"scroll"},
		{ k_artifact_seamans_hat,					"seamans_hat"},
		{ k_artifact_setting,						"setting"},
		{ k_artifact_shackles_of_war,				"shackles_of_war"},
		{ k_artifact_shield,						"shield"},
		{ k_artifact_shield_of_chaos,				"shield_of_chaos"},
		{ k_artifact_shield_of_darkness,			"shield_of_darkness"},
		{ k_artifact_shield_of_light,				"shield_of_light"},
		{ k_artifact_shield_of_order,				"shield_of_order"},
		{ k_artifact_shield_of_resistance,			"shield_of_resistance"},
		{ k_artifact_snipers_crossbow,				"snipers_crossbow"},
		{ k_artifact_snowshoes,						"snowshoes"},
		{ k_artifact_soul_stealer,					"soul_stealer"},
		{ k_artifact_spiders_silk_arrow,			"spiders_silk_arrow"},
		{ k_artifact_staads_scarab_of_summoning,	"staads_scarab_of_summoning"},
		{ k_artifact_staff_of_death,				"staff_of_death"},
		{ k_artifact_staff_of_enchantment,			"staff_of_enchantment"},
		{ k_artifact_staff_of_power,				"staff_of_power"},
		{ k_artifact_staff_of_summoning,			"staff_of_summoning"},
		{ k_artifact_staff_of_the_witch_king,		"staff_of_the_witch_king"},
		{ k_artifact_statesmans_medal,				"statesmans_medal"},
		{ k_artifact_statue_of_legion,				"statue_of_legion"},
		{ k_artifact_steadfast_shield,				"steadfast_shield"},
		{ k_artifact_supreme_crown_of_the_magi,		"supreme_crown_of_the_magi"},
		{ k_artifact_surefooted_boots,				"surefooted_boots"},
		{ k_artifact_swamp_boots,					"swamp_boots"},
		{ k_artifact_sword_of_swiftness,			"sword_of_swiftness"},
		{ k_artifact_sword_of_the_gods,				"sword_of_the_gods"},
		{ k_artifact_tavins_sling,					"tavins_sling"},
		{ k_artifact_telescope,						"telescope"},
		{ k_artifact_throwing_spear,				"throwing_spear"},
		{ k_artifact_thunder_hammer,				"thunder_hammer"},
		{ k_artifact_tome_of_chaos,					"tome_of_chaos"},
		{ k_artifact_tome_of_death,					"tome_of_death"},
		{ k_artifact_tome_of_life,					"tome_of_life"},
		{ k_artifact_tome_of_nature,				"tome_of_nature"},
		{ k_artifact_tome_of_order,					"tome_of_order"},
		{ k_artifact_torso_of_legion,				"torso_of_legion"},
		{ k_artifact_tynans_dagger_of_despair,		"tynans_dagger_of_despair"},
		{ k_artifact_unnatural_armor,				"unnatural_armor"},
		{ k_artifact_unnatural_shield,				"unnatural_shield"},
		{ k_artifact_valders_bow_of_sloth,			"valders_bow_of_sloth"},
		{ k_artifact_vampiric_amulet,				"vampiric_amulet"},
		{ k_artifact_vial_of_acid,					"vial_of_acid"},
		{ k_artifact_vial_of_blinding_smoke,		"vial_of_blinding_smoke"},
		{ k_artifact_vial_of_choking_gas,			"vial_of_choking_gas"},
		{ k_artifact_vial_of_poison,				"vial_of_poison"},
		{ k_artifact_vial_of_sulfur,				"vial_of_sulfur"},
		{ k_artifact_victory_banner,				"victory_banner"},
		{ k_artifact_wand_of_animate_dead,			"wand_of_animate_dead"},
		{ k_artifact_wand_of_bless,					"wand_of_bless"},
		{ k_artifact_wand_of_curse,					"wand_of_curse"},
		{ k_artifact_wand_of_fire,					"wand_of_fire"},
		{ k_artifact_wand_of_fireball,				"wand_of_fireball"},
		{ k_artifact_wand_of_haste,					"wand_of_haste"},
		{ k_artifact_wand_of_healing,				"wand_of_healing"},
		{ k_artifact_wand_of_ice,					"wand_of_ice"},
		{ k_artifact_wand_of_illusion,				"wand_of_illusion"},
		{ k_artifact_wand_of_weakness,				"wand_of_weakness"},
		{ k_artifact_warding_robe,					"warding_robe"},
		{ k_artifact_warlords_ring,					"warlords_ring"},
		{ k_artifact_winged_sandals,				"winged_sandals"},
		{ k_artifact_wizards_ring,					"wizards_ring"},

		{ k_artifact_breeze_the_falcon,				"breeze_the_falcon" },
		{ k_artifact_deadwood_staff,				"deadwood_staff" },
		{ k_artifact_true_gryphonheart_blade,		"true_gryphonheart_blade" },
		{ k_artifact_false_gryphonheart_blade,		"false_gryphonheart_blade" },

		{ k_artifact_grail,							"grail" },
	};

	t_char_ptr_pair const k_level_keywords[] =
	{
		{ k_artifact_level_item,		"item" },
		{ k_artifact_level_treasure,	"treasure" },
		{ k_artifact_level_minor,		"minor" },
		{ k_artifact_level_major,		"major" },
		{ k_artifact_level_fragment,	"fragment" },
		{ k_artifact_level_relic,		"relic" },
		{ k_artifact_level_divine,		"divine" },
	};

	typedef t_enum_map<t_artifact_slot>  t_slot_map;
	typedef t_enum_map<t_artifact_type>  t_artifact_map;
	typedef t_enum_map<t_artifact_level> t_level_map;

}; // unnamed namespace

static t_char_ptr_pair const k_slot_keywords[] =
{
	{ k_artifact_slot_bow,			"bow" },
	{ k_artifact_slot_feet,			"feet" },
	{ k_artifact_slot_head,			"head" },
	{ k_artifact_slot_left_ring,	"left ring" },
	{ k_artifact_slot_misc_1,		"misc_1" },
	{ k_artifact_slot_misc_2,		"misc_2" },
	{ k_artifact_slot_misc_3,		"misc_3" },
	{ k_artifact_slot_misc_4,		"misc_4" },
	{ k_artifact_slot_neck,			"neck" },
	{ k_artifact_slot_right_ring,	"right ring" },
	{ k_artifact_slot_shield,		"left hand" },
	{ k_artifact_slot_shoulders,	"shoulders" },
	{ k_artifact_slot_torso,		"torso" },
	{ k_artifact_slot_weapon,		"right hand" },

	{ k_artifact_slot_hero_count,	"invalid" },

	{ k_artifact_slot_2_handed,		"both hands" },
	{ k_artifact_slot_fragment,		"backpack" },
	{ k_artifact_slot_potion,		"potion" },
	{ k_artifact_slot_misc,			"miscellaneous" },
	{ k_artifact_slot_ring,			"ring" },
};

t_slot_map const& get_slot_map()
{
	static const t_slot_map map( k_slot_keywords, 
								 ELEMENTS_OF( k_slot_keywords ),
		                         k_artifact_slot_count );
	return map;
}

static const t_artifact_map k_artifact_map( k_artifact_keywords, 
									 ELEMENTS_OF( k_artifact_keywords ),
									 k_artifact_type_count );

t_level_map const& get_level_map()
{
	static const t_level_map map( k_level_keywords,
		                          ELEMENTS_OF( k_level_keywords ),
								  k_artifact_level_count );
	return map;
}

// -----------------------------------------------------------------
// get a keyword for a given artifact slot
// -----------------------------------------------------------------
char const* get_keyword( t_artifact_slot slot )
{
	return get_slot_map()[slot];
}

// -----------------------------------------------------------------
// match a keyword to a artifact slot
// -----------------------------------------------------------------
t_artifact_slot get_artifact_slot( std::string string )
{
	return get_slot_map()[string];
}

// -----------------------------------------------------------------
// get a keyword for a given artifact
// -----------------------------------------------------------------
char const* get_keyword( t_artifact_type artifact )
{
	return k_artifact_map[artifact];
}

// -----------------------------------------------------------------
// match a keyword to a artifact slot
// -----------------------------------------------------------------
t_artifact_type get_artifact_type( std::string string )
{
	return k_artifact_map[string];
}

// -----------------------------------------------------------------
// get a keyword for a given artifact level
// -----------------------------------------------------------------
char const* get_keyword( t_artifact_level level )
{
	return get_level_map()[level];
}

// -----------------------------------------------------------------
// match a keyword to a artifact level
// -----------------------------------------------------------------
t_artifact_level get_artifact_level( std::string string )
{
	return get_level_map()[string];
}

